package com.cmcc.pp.ui;

import android.os.Bundle;

import com.cmcc.pp.R;
import com.cmcc.pp.api.ParamTools;
import com.cmcc.pp.api.TestApi;
import com.cmcc.pp.base.BActivity;
import com.zrspring.libv2.network.Client;
import com.zrspring.libv2.network.RxUtils;
import com.zrspring.libv2.util.ToastUtils;
import com.zrspring.libv2.view.ProgressDlg;

import org.jetbrains.annotations.NotNull;

import io.reactivex.Observable;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;

/**
 * Created by shopping on 2017/12/25 15:05.
 * https://github.com/wheroj
 */

public class TestActivity2 extends BActivity {
    @Override
    protected boolean getHasTitle() {
        return true;
    }

    @Override
    public int getContentLayoutId() {
        return R.layout.activity_login;
    }

    @Override
    public void initView(Bundle savedInstanceState) {

    }

    @Override
    public void loadData() {
        ParamTools paramsTool = new ParamTools();
        paramsTool.addParam("userId", "65");
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), paramsTool.getParam());
        Observable<ResponseBody> testNet = Client.getApi(TestApi.class).testNet(requestBody);
        ProgressDlg progressDlg = new ProgressDlg(this, "登陆中......");
        RxUtils.INSTANCE.acquireString(testNet, new RxUtils.DefaultListener(progressDlg) {
            @Override
            public void onError(@NotNull Throwable e) {
                showError("加载出错了，轻点屏幕重试一下呢");
                ToastUtils.show(e.getMessage());
            }

            @Override
            public void onResult(@NotNull String result) {
                ToastUtils.show(result);
            }
        });
    }
}
